package com.example.demo.day.config.learn.designBook.part11Builder.part1;

import java.util.ArrayList;

public abstract class CarModel {

    //这个参数是各个基本方法执行的顺序
    private ArrayList<String> sequence = new ArrayList<String>();
    //模型是启动开始跑了
    protected abstract void start();
    //能发动，那还要能停下来
    protected abstract void stop();
    //喇叭会发出声音
    protected abstract void alarm();
    //引擎会轰隆隆的响
    protected abstract void engineBoom();
    //模型会跑
    final public void run() {
        for (int i = 0; i < this.sequence.size(); i++) {
            String actionName = this.sequence.get(i);
            if ("start".equals(actionName)) {
                this.start();  //开启汽车
            } else if ("stop".equals(actionName)) {
                this.stop();  //停止汽车
            } else if ("alarm".equals(actionName)) {
                this.alarm();  //喇叭开始叫
            } else if ("engine boom".equals(actionName)) {
                this.engineBoom();  //引擎开始轰鸣
            }
        }
    }

    //把传递过来的值传递到类内
    final public void setSequence(ArrayList<String> sequence) {
        this.sequence = sequence;
    }
}
